package com.sinopec.basemodule.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;

/**
 * @author lwj
 * @ClassName: DateUtil
 * @Description: 用来转换时间的工具类
 */
public class DateUtil {

    //date formats
    public static final String DATEFORMAT_STR0 = "yyyy-MM-dd HH:mm:ss.sss";
    public static final String DATEFORMAT_STR1 = "yyyy-MM-dd HH:mm:ss";
    public static final String DATEFORMAT_STR2 = "yyyy-MM-dd HH:mm";
    public static final String DATEFORMAT_STR7 = "yyyy-MM-dd HH";
    public static final String DATEFORMAT_STR3 = "yyyy-MM-dd";
    public static final String DATEFORMAT_STR4 = "yyyyMMdd";
    public static final String DATEFORMAT_STR5 = "yyMMdd";
    public static final String DATEFORMAT_STR6 = "yyyyMM";
    /**
     * 获取  当前年、半年、季度、月、日、小时 开始结束时间
     */
    private static SimpleDateFormat shortSdf;
    private static SimpleDateFormat longHourSdf;
    private static SimpleDateFormat longSdf;

    static {
        shortSdf = new SimpleDateFormat(DATEFORMAT_STR3);
        longHourSdf = new SimpleDateFormat(DATEFORMAT_STR7);
        longSdf = new SimpleDateFormat(DATEFORMAT_STR1);
    }

    /**
     * 时间转换方法
     *
     * @param date 传出一个String的时间
     * @return 获得年月日的时间(yyyy - MM - dd)
     */
    public static String formatDate(Date date) {
        //保存改后的时间
        String ymd = " ";
        if (date == null || "".equals(date) || "1900-01-01 00:00:00.0".equals(date)) {
            return ymd;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        ymd = dateFormat.format(date);
        return ymd;
    }

    /**
     * 根据字符串格式化为时间
     */
    public static String getDateFormat(String strDate, String formatType) {
        String ymd = " ";
        if (!EmptyUtils.isEmpty(strDate)) {
            try {
                SimpleDateFormat sdf = new SimpleDateFormat(formatType);
                Date dt = sdf.parse(strDate);
                return sdf.format(dt);
            } catch (ParseException e) {
                e.printStackTrace();
                return ymd;
            }
        } else {
            return ymd;
        }
    }


    /**
     * @param @param  date   Date类型的时间
     * @param @param  formatType 转换时间的类型
     * @param @return 设定文件
     * @return String    返回类型
     * @Description: Date类型转换成Sting
     */
    public static String formatDate(Date date, String formatType) {
        //保存改后的时间

        String ymd = " ";
        if (date == null || "".equals(date) || "1900-01-01 00:00:00.0".equals(date)) {
            return ymd;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat(formatType);
        ymd = dateFormat.format(date);
        return ymd;
    }

    /**
     * @param @param  str_date   String类型的时间
     * @param @param  formatType 转换时间的类型
     * @param @return 设定文件
     * @return Date    返回类型
     * @Title: formatDate
     * @Description: Sting类型转换成Date
     */
    public static Date formatDate(String str_date, String formatType) {
        if (str_date == null || "".equals(str_date) || "1900-01-01 00:00:00".equals(str_date)) {
            return null;
        }
        SimpleDateFormat formatter = new SimpleDateFormat(formatType);
        Date date = null;
        try {
            date = formatter.parse(str_date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * @return 当前时间年
     */
    public static String getYear() {
        return getCurrentDateTime("yyyy");
    }

    /**
     * 获得给定时间的月分的会后一天
     *
     * @return 天数
     */
    public static int monthLastDay(GregorianCalendar calendar) {

        int lastDay = 0;
        GregorianCalendar gregorian = calendar;
        int month = gregorian.get(Calendar.MONTH);
        do {
            lastDay = gregorian.get(Calendar.DAY_OF_MONTH);
            gregorian.add(Calendar.DAY_OF_MONTH, 1);
        } while (gregorian.get(Calendar.MONTH) == month);
        return lastDay;
    }

    /**
     * 返回这个月的最大Date
     *
     * @return YYYY-MM-dd
     */
    public static String getMonthLastDaDate() {
        StringBuffer datetime = new StringBuffer();
        GregorianCalendar calendar = new GregorianCalendar();
        datetime.append(calendar.get(Calendar.YEAR));
        datetime.append("-");
        if (calendar.get(Calendar.MONTH) < 9) {
            datetime.append("0");
        }
        datetime.append((calendar.get(Calendar.MONTH) + 1));
        datetime.append("-");
        datetime.append(monthLastDay(calendar));
        return datetime.toString();
    }

    /**
     * 返回这个月的最小Date
     *
     * @return YYYY-MM-dd
     */
    public static String getMonthLeastDaDate() {
        StringBuffer datetime = new StringBuffer();
        GregorianCalendar calendar = new GregorianCalendar();
        datetime.append(calendar.get(Calendar.YEAR));
        datetime.append("-");
        if (calendar.get(Calendar.MONTH) < 9) {
            datetime.append("0");
        }
        datetime.append((calendar.get(Calendar.MONTH) + 1));
        datetime.append("-");
        datetime.append("01");
        return datetime.toString();
    }

    /**
     * 获得当前日期YYYY-MM-dd
     *
     * @return YYYY-MM-dd
     */
    public String getFormatDate() {
        StringBuffer datetime = new StringBuffer();
        GregorianCalendar calendar = new GregorianCalendar();
        datetime.append(calendar.get(Calendar.YEAR));
        datetime.append("-");
        if (calendar.get(Calendar.MONTH) < 9) {
            datetime.append("0");
        }
        datetime.append((calendar.get(Calendar.MONTH) + 1));
        datetime.append("-");
        if (calendar.get(Calendar.DAY_OF_MONTH) < 10) {
            datetime.append("0");
        }
        datetime.append(calendar.get(Calendar.DAY_OF_MONTH));
        return datetime.toString();
    }

    /**
     * 获得 XXXX年XX月XX日XX分XX秒 格式的的时间
     */
    public String getFormatTime() {
        StringBuffer datetime = new StringBuffer();
        GregorianCalendar calendar = new GregorianCalendar();
        datetime.append(calendar.get(Calendar.YEAR));
        datetime.append("年");
        datetime.append((calendar.get(Calendar.MONTH) + 1));
        datetime.append("月");
        datetime.append(calendar.get(Calendar.DAY_OF_MONTH));
        datetime.append("日");
        datetime.append(calendar.get(Calendar.MINUTE));
        datetime.append("分");
        datetime.append(calendar.get(Calendar.SECOND));
        datetime.append("秒");
        return datetime.toString();
    }

    /**
     * 获得 当前日期YYYYMMdd
     */
    public static String getDate() {
        StringBuffer datetime = new StringBuffer();
        GregorianCalendar calendar = new GregorianCalendar();
        datetime.append(calendar.get(Calendar.YEAR));
        if (calendar.get(Calendar.MONTH) < 9) {
            datetime.append("0");
        }
        datetime.append((calendar.get(Calendar.MONTH) + 1));
        if (calendar.get(Calendar.DAY_OF_MONTH) < 10) {
            datetime.append("0");
        }
        datetime.append(calendar.get(Calendar.DAY_OF_MONTH));
        return datetime.toString();
    }


    /**
     * 获得当前时间 HH:MM
     */
    public String getTime() {
        StringBuffer datetime = new StringBuffer();
        GregorianCalendar calendar = new GregorianCalendar();
        datetime.append(calendar.get(Calendar.HOUR_OF_DAY));
        datetime.append(":");
        datetime.append(calendar.get(Calendar.MINUTE));
        return datetime.toString();
    }

    /**
     * 获得当前时间 HHmmss
     */
    public static String getFullTimeNotDate() {
        return getCurrentDateTime("HHmmss");
    }

    /**
     * 获得当前时间 HHmmss
     */
    public static String getFullTimeByTwoPonit() {
        return getCurrentDateTime("HH:mm:ss");
    }

    /**
     * 获得当前时间 yyyyMMdd
     *
     * @return
     */
    public static String getFullDate() {
        return getCurrentDateTime("yyyyMMdd");
    }

    /**
     * 获得当前时间 yyyy-MM-dd
     */
    public static String getFullDate_() {
        return getCurrentDateTime("yyyy-MM-dd");
    }

    /**
     * 根据格式返回当前日期时间
     */
    public static String getCurrentDateTime(String format) {
        SimpleDateFormat df = new SimpleDateFormat(format);
        return df.format(new Date());
    }

    /**
     * 返回星期
     */
    public static String getWeekay() {
        String dayNames[] = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
        Calendar cal = Calendar.getInstance();
        int day = cal.get(Calendar.DAY_OF_WEEK);
        String week_day = dayNames[day - 1];
        return week_day;
    }

    public static String getDateDay() {
        SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日");
        return df.format(new Date());
    }

    public static String dateFormat(Date date, String format) {
        if (EmptyUtils.isNull(date)) {
            return null;
        }
        SimpleDateFormat df = new SimpleDateFormat(format);
        return df.format(date);
    }

    /**
     * 返回YYYY-MM-dd
     */
    public static String getStrDate(String date) {
        String y = date.substring(0, 4);
        String m = date.substring(4, 6);
        String d = date.substring(6, 8);
        StringBuffer newDate = new StringBuffer();
        newDate.append(y).append("-").append(m).append("-").append(d);
        return newDate.toString();
    }

    /**
     * 返回MM/dd
     */
    public static String getDateStr(String date) {
        String y = date.substring(0, 4);
        String m = date.substring(4, 6);
        String d = date.substring(6, 8);
        StringBuffer newDate = new StringBuffer();
        newDate.append(m).append("/").append(d);
        return newDate.toString();
    }

    /**
     * 返回MM/dd
     */
    public static String getTimeStr(String date) {
        String y = date.substring(0, 4);
        String m = date.substring(4, 6);
        String d = date.substring(6, 8);
        String h = date.substring(8, 10);
        String mm = date.substring(10, 12);
        String s = date.substring(12, 14);
        StringBuffer newDate = new StringBuffer();
        newDate.append(h).append(":").append(mm);
        return newDate.toString();
    }

    /**
     * 返回YYYY-MM-dd
     */
    public static String getStrDateTime(String date) {
        String y = date.substring(0, 4);
        String m = date.substring(4, 6);
        String d = date.substring(6, 8);
        StringBuffer newDate = new StringBuffer();
        newDate.append(y).append("-").append(m).append("-").append(d).append(" ");
        String h = date.substring(8, 10);
        String mm = date.substring(10, 12);
        String s = date.substring(12, 14);
        newDate.append(h).append(":").append(mm).append(":").append(s);
        return newDate.toString();
    }

    /**
     * 返回HH:mm:ss
     */
    public static String getStrtime(String date) {
        String y = date.substring(0, 2);
        String m = date.substring(2, 4);
        String d = date.substring(4, 6);
        StringBuffer newDate = new StringBuffer();
        newDate.append(y).append(":").append(m).append(":").append(d);
        return newDate.toString();
    }

    /**
     * 判断是否为现在日期
     */
    public static boolean isCurrent(String date) {
        boolean flag = true;
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
            Date dt = df.parse(date);
            Calendar cal = Calendar.getInstance();
            cal.setTime(dt);
            Calendar currentDate = Calendar.getInstance();
            if (currentDate.get(Calendar.YEAR) != cal.get(Calendar.YEAR)
                    || currentDate.get(Calendar.MONTH) != cal.get(Calendar.MONTH)
                    || currentDate.get(Calendar.DATE) != cal.get(Calendar.DATE)) {
                flag = false;
            }
        } catch (ParseException e) {
        }
        return flag;
    }

    public static Calendar stringToCalendar(String date) {
        Calendar cal = Calendar.getInstance();
        try {
            SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
            Date dt = df.parse(date);
            cal.setTime(dt);
        } catch (ParseException e) {
        }
        return cal;
    }

    public static String calendarToString(Calendar cal) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        return sdf.format(cal.getTime());
    }

    /**
     * 获取完整的时间日期
     */
    public static String getFullTime() {
        return getCurrentDateTime("yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 获取完整的时间日期
     */
    public static String getYM() {
        return getCurrentDateTime("yyyy-MM");
    }

    /**
     * 获取完整的时间日期
     */
    public static String getYearM() {
        return getCurrentDateTime("yyyyMM");
    }

    /**
     * 获取完整的时间日期时间yyyyMMddHHmmss
     */
    public static String getFullString() {
        return getCurrentDateTime("yyyyMMddHHmmss");
    }

    /**
     * 根据字符串格式化为时间
     */
    public static Date getDateFormat(String format) {
        if (format == null || "".equals(format)) {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            try {
                return sdf.parse(format);
            } catch (ParseException e) {
                e.printStackTrace();
                return new Date();
            }
        } else {
            return new Date();
        }
    }

    // 获得本周第一天的日期
    public static String getWeekFirstDate() {
        SimpleDateFormat df = new SimpleDateFormat(DATEFORMAT_STR3);
        Calendar cal = Calendar.getInstance();
        int day_of_week = cal.get(Calendar.DAY_OF_WEEK) - 2;
        cal.add(Calendar.DATE, -day_of_week);
        return df.format(cal.getTime());
    }

    // 获得本周末的日期
    public static String getWeekLastDate() {
        SimpleDateFormat df = new SimpleDateFormat(DATEFORMAT_STR3);
        Calendar cal = Calendar.getInstance();
        int day_of_week = cal.get(Calendar.DAY_OF_WEEK) - 2;
        cal.add(Calendar.DATE, -day_of_week);
        cal.add(Calendar.DATE, 6);
        return df.format(cal.getTime());
    }

    public static List<String> getAllDate(String start, String end) throws Exception {
        List<String> list = new ArrayList<String>();
        Date dateTemp = new SimpleDateFormat("yyyy-MM-dd").parse(start);
        Date dateTemp2 = new SimpleDateFormat("yyyy-MM-dd").parse(end);
        Calendar calendarTemp = Calendar.getInstance();
        calendarTemp.setTime(dateTemp);
        while (calendarTemp.getTime().getTime() <= dateTemp2.getTime()) {
            list.add(new SimpleDateFormat("yyyy-MM-dd").format(calendarTemp.getTime()));
            calendarTemp.add(Calendar.DAY_OF_YEAR, 1);
        }
        return list;
    }

    /**
     * 获得本小时的开始时间，即2012-01-01 23:59:59
     */
    public static Date getCurrentHourStartTime() {
        Date now = new Date();
        try {
            now = longHourSdf.parse(longHourSdf.format(now));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 获得本小时的结束时间，即2012-01-01 23:59:59
     */
    public static Date getCurrentHourEndTime() {
        Date now = new Date();
        try {
            now = longSdf.parse(longHourSdf.format(now) + ":59:59");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 获得本天的开始时间，即2012-01-01 00:00:00
     */
    public static Date getCurrentDayStartTime() {
        Date now = new Date();
        try {
            now = shortSdf.parse(shortSdf.format(now));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 获得本天的结束时间，即2012-01-01 23:59:59
     */
    public static Date getCurrentDayEndTime() {
        Date now = new Date();
        try {
            now = longSdf.parse(shortSdf.format(now) + " 23:59:59");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 获得昨天的开始时间，即2012-01-01 00:00:00
     */
    public static String getYesterdayDayStartTime() {
        SimpleDateFormat df = new SimpleDateFormat(DATEFORMAT_STR3);
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);
        return df.format(cal.getTime()) + " 00:00:00";
    }

    /**
     * 获得昨天的开始时间，即2012-01-01 00:00:00
     */
    public static String getYesterdayDayEndTime() {
        SimpleDateFormat df = new SimpleDateFormat(DATEFORMAT_STR3);
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.DATE, -1);
        return df.format(cal.getTime()) + " 23:59:59";
    }

    /**
     * 获得本周的第一天，周一
     */
    public static Date getCurrentWeekDayStartTime() {
        Calendar c = Calendar.getInstance();
        try {
            int weekday = c.get(Calendar.DAY_OF_WEEK) - 2;
            c.add(Calendar.DATE, -weekday);
            c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return c.getTime();
    }

    /**
     * 获得本周的最后一天，周日
     */
    public static Date getCurrentWeekDayEndTime() {
        Calendar c = Calendar.getInstance();
        try {
            int weekday = c.get(Calendar.DAY_OF_WEEK);
            c.add(Calendar.DATE, 8 - weekday);
            c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return c.getTime();
    }

    /**
     * 获得本月的开始时间，即2012-01-01 00:00:00
     */
    public static Date getCurrentMonthStartTime() {
        Calendar c = Calendar.getInstance();
        Date now = null;
        try {
            c.set(Calendar.DATE, 1);
            now = shortSdf.parse(shortSdf.format(c.getTime()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 当前月的结束时间，即2012-01-31 23:59:59
     */
    public static Date getCurrentMonthEndTime() {
        Calendar c = Calendar.getInstance();
        Date now = null;
        try {
            c.set(Calendar.DATE, 1);
            c.add(Calendar.MONTH, 1);
            c.add(Calendar.DATE, -1);
            now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 当前年的开始时间，即2012-01-01 00:00:00
     */
    public static Date getCurrentYearStartTime() {
        Calendar c = Calendar.getInstance();
        Date now = null;
        try {
            c.set(Calendar.MONTH, 0);
            c.set(Calendar.DATE, 1);
            now = shortSdf.parse(shortSdf.format(c.getTime()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 当前年的结束时间，即2012-12-31 23:59:59
     */
    public static Date getCurrentYearEndTime() {
        Calendar c = Calendar.getInstance();
        Date now = null;
        try {
            c.set(Calendar.MONTH, 11);
            c.set(Calendar.DATE, 31);
            now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 当前季度的开始时间，即2012-01-1 00:00:00
     */
    public static Date getCurrentQuarterStartTime() {
        Calendar c = Calendar.getInstance();
        int currentMonth = c.get(Calendar.MONTH) + 1;
        Date now = null;
        try {
            if (currentMonth >= 1 && currentMonth <= 3)
                c.set(Calendar.MONTH, 0);
            else if (currentMonth >= 4 && currentMonth <= 6)
                c.set(Calendar.MONTH, 3);
            else if (currentMonth >= 7 && currentMonth <= 9)
                c.set(Calendar.MONTH, 4);
            else if (currentMonth >= 10 && currentMonth <= 12)
                c.set(Calendar.MONTH, 9);
            c.set(Calendar.DATE, 1);
            now = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 当前季度的结束时间，即2012-03-31 23:59:59
     */
    public static Date getCurrentQuarterEndTime() {
        Calendar c = Calendar.getInstance();
        int currentMonth = c.get(Calendar.MONTH) + 1;
        Date now = null;
        try {
            if (currentMonth >= 1 && currentMonth <= 3) {
                c.set(Calendar.MONTH, 2);
                c.set(Calendar.DATE, 31);
            } else if (currentMonth >= 4 && currentMonth <= 6) {
                c.set(Calendar.MONTH, 5);
                c.set(Calendar.DATE, 30);
            } else if (currentMonth >= 7 && currentMonth <= 9) {
                c.set(Calendar.MONTH, 4);
                c.set(Calendar.DATE, 30);
            } else if (currentMonth >= 10 && currentMonth <= 12) {
                c.set(Calendar.MONTH, 11);
                c.set(Calendar.DATE, 31);
            }
            now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * 获取前/后半年的开始时间
     */
    public static Date getHalfYearStartTime() {
        Calendar c = Calendar.getInstance();
        int currentMonth = c.get(Calendar.MONTH) + 1;
        Date now = null;
        try {
            if (currentMonth >= 1 && currentMonth <= 6) {
                c.set(Calendar.MONTH, 0);
            } else if (currentMonth >= 7 && currentMonth <= 12) {
                c.set(Calendar.MONTH, 6);
            }
            c.set(Calendar.DATE, 1);
            now = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;

    }

    /**
     * 获取前/后半年的结束时间
     */
    public static Date getHalfYearEndTime() {
        Calendar c = Calendar.getInstance();
        int currentMonth = c.get(Calendar.MONTH) + 1;
        Date now = null;
        try {
            if (currentMonth >= 1 && currentMonth <= 6) {
                c.set(Calendar.MONTH, 5);
                c.set(Calendar.DATE, 30);
            } else if (currentMonth >= 7 && currentMonth <= 12) {
                c.set(Calendar.MONTH, 11);
                c.set(Calendar.DATE, 31);
            }
            now = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return now;
    }

    /**
     * @author lwj
     * @Description: 将传出时间与当前时间进行对比，是否今天、明天、后天
     */
    public static String getChineseTime(String dateStr) {
        String time = DateUtil.getDateFormat(dateStr, DateUtil.DATEFORMAT_STR2);
        if (EmptyUtils.isEmpty(time)) {
            return time;
        }
        Date date = DateUtil.formatDate(dateStr, DateUtil.DATEFORMAT_STR2);
        if (EmptyUtils.isNull(date)) {
            return time;
        }
        String todySDF = "yyyy-MM-dd （今天）HH:mm";
        String tomorrowSDF = "yyyy-MM-dd （明天）HH:mm";
        String afterDaySDF = "yyyy-MM-dd （后天）HH:mm";
        SimpleDateFormat sfd = null;
        Calendar dateCalendar = Calendar.getInstance();
        dateCalendar.setTime(date);
        Date now = new Date();
        Calendar nowCalendar = Calendar.getInstance();
        nowCalendar.setTime(now);
        nowCalendar.set(Calendar.HOUR_OF_DAY, 0);
        nowCalendar.set(Calendar.MINUTE, 0);
        nowCalendar.set(Calendar.SECOND, 0);
		/*String s1=DateUtil.formatDate(nowCalendar.getTime(),DateUtil.DATEFORMAT_STR1);
		System.out.println("nowCalendar="+s1);*/

        Calendar yesterdayCalendar = Calendar.getInstance();
        yesterdayCalendar.setTime(now);
        yesterdayCalendar.add(Calendar.DATE, -1);
        yesterdayCalendar.set(Calendar.HOUR_OF_DAY, 0);
        yesterdayCalendar.set(Calendar.MINUTE, 0);
        yesterdayCalendar.set(Calendar.SECOND, 0);
		/*String s0=DateUtil.formatDate(yesterdayCalendar.getTime(),DateUtil.DATEFORMAT_STR1);
		System.out.println("yesterdayCalendar="+s0);*/

        Calendar tomorrowCalendar = Calendar.getInstance();
        tomorrowCalendar.setTime(now);
        tomorrowCalendar.add(Calendar.DATE, 1);
        tomorrowCalendar.set(Calendar.HOUR_OF_DAY, 0);
        tomorrowCalendar.set(Calendar.MINUTE, 0);
        tomorrowCalendar.set(Calendar.SECOND, 0);
		/*String s2=DateUtil.formatDate(tomorrowCalendar.getTime(),DateUtil.DATEFORMAT_STR1);
		System.out.println("tomorrowCalendar="+s2);*/

        Calendar afterCalendar = Calendar.getInstance();
        afterCalendar.setTime(now);
        afterCalendar.add(Calendar.DATE, 2);
        afterCalendar.set(Calendar.HOUR_OF_DAY, 0);
        afterCalendar.set(Calendar.MINUTE, 0);
        afterCalendar.set(Calendar.SECOND, 0);
		/*String s3=DateUtil.formatDate(afterCalendar.getTime(),DateUtil.DATEFORMAT_STR1);
		System.out.println("afterCalendar="+s3);*/

        Calendar afterbigCalendar = Calendar.getInstance();
        afterbigCalendar.setTime(now);
        afterbigCalendar.add(Calendar.DATE, 3);
        afterbigCalendar.set(Calendar.HOUR_OF_DAY, 0);
        afterbigCalendar.set(Calendar.MINUTE, 0);
        afterbigCalendar.set(Calendar.SECOND, 0);
		/*String s4=DateUtil.formatDate(afterbigCalendar.getTime(),DateUtil.DATEFORMAT_STR1);
		System.out.println("afterbigCalendar="+s4);*/

        if (dateCalendar.after(nowCalendar) && dateCalendar.before(tomorrowCalendar)) {//今天
            sfd = new SimpleDateFormat(todySDF);
            time = sfd.format(date);
            return time;
        } else if (dateCalendar.after(tomorrowCalendar) && dateCalendar.before(afterCalendar)) {//明天
            sfd = new SimpleDateFormat(tomorrowSDF);
            time = sfd.format(date);
            return time;
        } else if (dateCalendar.after(afterCalendar) && dateCalendar.before(afterbigCalendar)) {//后天
            sfd = new SimpleDateFormat(afterDaySDF);
            time = sfd.format(date);
            return time;
        }
        return time;
    }

    //判断选择的日期是否是今天
    public static boolean isToday(String timeStr) {
        return isThisTime(timeStr, "yyyy年MM月dd");
    }

    //判断选择的日期是否是本周
    public static boolean isThisWeek(long time) {
        Calendar calendar = Calendar.getInstance();
        int currentWeek = calendar.get(Calendar.WEEK_OF_YEAR);
        calendar.setTime(new Date(time));
        int paramWeek = calendar.get(Calendar.WEEK_OF_YEAR);
        if (paramWeek == currentWeek) {
            return true;
        }
        return false;
    }

    //判断选择的日期是否是本月
    public static boolean isThisMonth(String timeStr) {
        return isThisTime(timeStr, "yyyy年MM月");
    }

    //判断选择的日期是否是本年
    public static boolean isThisYear(String timeStr) {
        return isThisTime(timeStr, "yyyy");
    }

    public static boolean isThisTime(String timeStr, String pattern) {
        Date date = DateUtil.formatDate(timeStr, DateUtil.DATEFORMAT_STR3);
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        String param = sdf.format(date);//参数时间
        String now = sdf.format(new Date());//当前时间
        if (param.equals(now)) {
            return true;
        }
        return false;
    }

    /**
     * 日期字符串转时间戳
     */
    public static Long string2Millis(String dateStr, String formatStr) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(formatStr);
            return simpleDateFormat.parse(dateStr).getTime();
        } catch (Exception e) {
            return 0L;
        }
    }

    // 测试方法
    public static void main(String[] args) {
        // 创建 Calendar 对象
		/*Calendar calendar = Calendar.getInstance();
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		// 指定一个日期
		try {
			Date date = dateFormat.parse("2018-6-1 13:24:16");
			calendar.setTime(date);
			System.out.println(calendar.YEAR+" "+calendar.MONTH+" "+calendar.DATE+" "+calendar.HOUR+" "+calendar.MINUTE+" "+calendar.SECOND);
		} catch (ParseException e) {
			e.printStackTrace();
		}*/
        Calendar c = Calendar.getInstance();//可以对每个时间域单独修改

        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int date = c.get(Calendar.DATE);
        int hour = c.get(Calendar.HOUR_OF_DAY);
        int minute = c.get(Calendar.MINUTE);
        int second = c.get(Calendar.SECOND);
        System.out.println(year + "/" + month + "/" + date + " " + hour + ":" + minute + ":" + second);
        // 对 calendar 设置为 date 所定的日期

		/*System.out.println(getDateStr("20181010 12:12:22"));
		System.out.println(getTimeStr("20181010 12:12:22"));*/
     	/*SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date dt = sdf.parse("2018-10-10 20:10:10");
            System.out.println(sdf.format(dt));
        } catch (ParseException e) {
            e.printStackTrace();
        }*/

        /*String time="1256006105375";
		Date date=new Date(Long.parseLong(time));
		SimpleDateFormat formatter=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		time=formatter.format(date);
		System.out.println(time);*/

        //System.out.println("ss="+DateUtil.getDateFormat("2018-10-10 20:10:10","yyyy-MM-dd HH:mm:ss"));
        //System.out.println(DateUtil.getChineseTime("2018-10-19 12:22"));
//		System.out.println("ss="+DateUtil.getChineseTime(""));
        //System.out.println(DateUtil.getChineseTime("2018-05-12 22:12"));
//		System.out.println(DateUtil.getChineseTime("2018-05-13 22:13"));
//		System.out.println(DateUtil.getChineseTime("2018-05-14 22:14"));
//		System.out.println(DateUtil.getChineseTime("2018-05-15 22:15"));
		/*System.out.println("这个月的最小Date"+getMonthLeastDaDate() + " 00:00:00");
		System.out.println("这个月的最大Date"+getMonthLastDaDate() + " 23:59:59");
		System.out.println("单日getDate="+getDate() + " 00:00:00");
		System.out.println("单日getDateDay="+getDateDay()+ " 00:00:00");
		System.out.println("单日getFullDate"+getFullDate()+ " 00:00:00");
		System.out.println("单日getFullDate_"+getFullDate_()+ " 00:00:00");
		System.out.println("本周第一天: " + getWeekFirstDate()+ " 00:00:00");
		System.out.println("本周末: " + getWeekLastDate()+ " 23:59:59");*/
		/*SimpleDateFormat df=new SimpleDateFormat(DATEFORMAT_STR3);
		Calendar cal = Calendar.getInstance();
		System.out.println("今天的日期: " + cal.getTime());

		int day_of_week = cal.get(Calendar.DAY_OF_WEEK) - 2;
		cal.add(Calendar.DATE, -day_of_week);
		System.out.println("本周第一天: " + df.format(cal.getTime()));

		cal.add(Calendar.DATE, 6);
		System.out.println("本周末: " + df.format(cal.getTime()));*/
    }

}
